package com.neusoft.SPNursingHome.controller;

import com.neusoft.SPNursingHome.po.Bed;
import com.neusoft.SPNursingHome.po.Client;
import com.neusoft.SPNursingHome.po.MealSet;
import com.neusoft.SPNursingHome.po.ResponseBean;
import com.neusoft.SPNursingHome.service.BedService;
import com.neusoft.SPNursingHome.service.ClientService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/beds")
public class BedController {

    @Resource
    private BedService bedService;
    @Resource
    private ClientService clientService;

    @GetMapping("/by-room/{roomId}")
    public ResponseBean<List<Client>> getClientsInRoom(@PathVariable String roomId) {
        return clientService.getClientsByRoom(roomId);
    }

    @GetMapping("/floors")
    public ResponseBean<List<String>> getFloors() {
        return bedService.getAllFloors();
    }

    @GetMapping("/available")
    public ResponseBean<Map<String, List<Bed>>> getAvailableBedsByFloor(@RequestParam String floorId) {
        return bedService.findAvailableBedsByFloor(floorId);
    }

     // 获取指定楼层的床位图表数据
    @GetMapping("/chart")
    public ResponseBean<Map<String, Object>> getBedChart(@RequestParam String floorId) {
        return bedService.getBedChartByFloor(floorId);
    }

    /**
     * GET /bed/freeRooms
     * 返回当前所有有空闲床的房间号列表
     */
    @GetMapping("/freeRooms")
    public ResponseBean<List<String>> getFreeRooms() {
        return bedService.listRoomsWithFreeBeds();
    }

    /**
     * GET /bed/freeBeds
     * 根据 ?roomId=xxx 参数，返回该房间下所有空闲床对象列表
     */
    @GetMapping("/freeBeds")
    public ResponseBean<List<Bed>> getFreeBedsByRoom(@RequestParam String roomId) {
        return bedService.listFreeBedsByRoom(roomId);
    }

    @PutMapping("/update")
    public ResponseBean<Void> update(@RequestBody Bed bed) {
        return bedService.update(bed);
    }
}

